package br.com.portalecbahia.dao;


import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import br.com.portalecbahia.util.PortalECBahiaUtil;

public class NotificationDAO {

	private Context context;
	private SQLiteDatabase database;
	private DBHelper dbHelper;

	public NotificationDAO(Context context) {
		this.context = context;
	}

	public NotificationDAO openWritable() throws SQLException {
		dbHelper = new DBHelper(context);
		database = dbHelper.getWritableDatabase();
		return this;
	}
	public NotificationDAO openReadable() throws SQLException {
		dbHelper = new DBHelper(context);
		database = dbHelper.getReadableDatabase();
		return this;
	}
	

	public void close() {
		dbHelper.close();
	}
	
	
	public void update(Integer enable)  {
		this.openWritable();
		Cursor cursor = null;
		try{ 
			cursor = database.rawQuery("UPDATE tbl_notification SET ENABLE="+enable, null);
					
			cursor.moveToFirst();
			cursor.close();
			
		}catch (SQLException e) {
			Log.e(PortalECBahiaUtil.TAG, e.toString());
		}
		
		this.close();
		
	}
	
	public Boolean findStatusNotification () {
		this.openReadable();

		Boolean result = false;		
		Cursor cursor;
			 
		try{
			cursor = database.rawQuery("SELECT ENABLE FROM tbl_notification;", null);
			cursor.moveToFirst();
			if (!cursor.isAfterLast()){
				if (cursor.getInt(0) == 1) {
					result = true;
				} 
			}
			
			cursor.close();
		}catch (SQLException e){
			Log.e(PortalECBahiaUtil.TAG, e.toString());
		}
		
		this.close();
		
		return result;
	}
	
	


}
